var blockly3 = {
		initBlockly:function(){
			Blockly.Blocks['math_number_property'] = {
					  /**
					   * Block for checking if a number is even, odd, prime, whole, positive,
					   * negative or if it is divisible by certain number.
					   * @this Blockly.Block
					   */
					  init: function() {
					    var PROPERTIES =
					        [[Blockly.Msg.MATH_IS_EVEN, 'EVEN'],
					         [Blockly.Msg.MATH_IS_ODD, 'ODD'],
					         [Blockly.Msg.MATH_IS_PRIME, 'PRIME'],
					         [Blockly.Msg.MATH_IS_WHOLE, 'WHOLE'],
					         [Blockly.Msg.MATH_IS_POSITIVE, 'POSITIVE'],
					         [Blockly.Msg.MATH_IS_NEGATIVE, 'NEGATIVE'],
					         [Blockly.Msg.MATH_IS_DIVISIBLE_BY, 'DIVISIBLE_BY']];
					    this.setColour(Blockly.Blocks.math.HUE);
					    this.appendValueInput('NUMBER_TO_CHECK')
					        .setCheck('Number');
					    var dropdown = new Blockly.FieldDropdown(PROPERTIES, function(option) {
					      var divisorInput = (option == 'DIVISIBLE_BY');
					      this.sourceBlock_.updateShape_(divisorInput);
					    });
					    this.appendDummyInput()
					        .appendField(dropdown, 'PROPERTY');
					    //this.setInputsInline(true);
					    this.setOutput(true, 'Boolean');
					    this.setTooltip(Blockly.Msg.MATH_IS_TOOLTIP);
					  },
					  /**
					   * Create XML to represent whether the 'divisorInput' should be present.
					   * @return {Element} XML storage element.
					   * @this Blockly.Block
					   */
					  mutationToDom: function() {
					    var container = document.createElement('mutation');
					    var divisorInput = (this.getFieldValue('PROPERTY') == 'DIVISIBLE_BY');
					    container.setAttribute('divisor_input', divisorInput);
					    return container;
					  },
					  /**
					   * Parse XML to restore the 'divisorInput'.
					   * @param {!Element} xmlElement XML storage element.
					   * @this Blockly.Block
					   */
					  domToMutation: function(xmlElement) {
					    var divisorInput = (xmlElement.getAttribute('divisor_input') == 'true');
					    this.updateShape_(divisorInput);
					  },
					  /**
					   * Modify this block to have (or not have) an input for 'is divisible by'.
					   * @param {boolean} divisorInput True if this block has a divisor input.
					   * @private
					   * @this Blockly.Block
					   */
					  updateShape_: function(divisorInput) {
					    // Add or remove a Value Input.
					    var inputExists = this.getInput('DIVISOR');
					    if (divisorInput) {
					      if (!inputExists) {
					        this.appendValueInput('DIVISOR')
					            .setCheck('Number');
					      }
					    } else if (inputExists) {
					      this.removeInput('DIVISOR');
					    }
					  }
					};
			Blockly.Blocks['var'] = {
			  init: function() {
				var method = [["ref", "ref"], ["cross", "cross"], ["last", "last"], ["barslast", "barslast"], ["mema", "mema"], ["history_min", "history_min"]];
				var dropdown = new Blockly.FieldDropdown(method,function(option){
					 var divisorInput = option;
				     this.sourceBlock_.updateShape_(divisorInput);
				});
			    this.appendValueInput("param1")
			        .setCheck(null)
			        .appendField("self.")
			        .appendField(dropdown,"method")
			        .appendField("(");
			    this.appendValueInput("param2")
			        .setCheck(null)
			        .appendField(",");
			    this.appendValueInput("param3")
			        .setCheck(null)
			        .appendField(",");
			    this.appendDummyInput("dummyInput")
			        .appendField(")");
			    this.setTooltip('');
			    this.setColour(100);
			    this.setHelpUrl('http://www.example.com/');
			  },
			  /**
			   * Create XML to represent whether the 'divisorInput' should be present.
			   * @return {Element} XML storage element.
			   * @this Blockly.Block
			   */
			  mutationToDom: function() {
			    var container = document.createElement('mutation');
			    var divisorInput = this.getFieldValue('method');
			    container.setAttribute('divisor_input', divisorInput);
			    return container;
			  },
			  /**
			   * Parse XML to restore the 'divisorInput'.
			   * @param {!Element} xmlElement XML storage element.
			   * @this Blockly.Block
			   */
			  domToMutation: function(xmlElement) {
			    var divisorInput = xmlElement.getAttribute('divisor_input');
			    this.updateShape_(divisorInput);
			  },
			  /**
			   * Modify this block to have (or not have) an input for 'is divisible by'.
			   * @param {boolean} divisorInput True if this block has a divisor input.
			   * @private
			   * @this Blockly.Block
			   */
			  updateShape_: function(divisorInput) {
				  this.setOutput(true, null);
				  this.removeInput("dummyInput");
				  var param4 = this.getInput("param4");
				  var param3 = this.getInput("param3");
				  var param2 = this.getInput("param2");
				  if(!param2){
					  this.appendValueInput("param2")
				  	  .setCheck(null)
				  	  .appendField(","); 
				  }
				  if(!param3){
					  this.appendValueInput("param3")
				  	  .setCheck(null)
				  	  .appendField(","); 
				  }
				  if(divisorInput=='cross' || divisorInput=='last'){
					  if(!param4){
						 
						  this.appendValueInput("param4")
						  	  .setCheck(null)
						  	  .appendField(",");
					  }
				  }else if(divisorInput=='history_min'){
					  this.removeInput("param2");
					  this.removeInput("param3");
					  this.removeInput("param4")
				  }else if(divisorInput=='barslast' || divisorInput=='mema'){
					  this.removeInput("param3");
					  this.removeInput("param4")
				  }else{
					  this.setOutput(false, null);
					  this.removeInput("param4")
				  }
				  this.appendDummyInput("dummyInput")
			  	  .appendField(")");
			  }
			};
			Blockly.Python['var'] = function(block) {
			  var paramArr = [];
			  var dropdown_name = block.getFieldValue('method');
			  var value_param1 = Blockly.Python.valueToCode(block, 'param1', Blockly.Python.ORDER_ATOMIC);
			  var value_param2 = Blockly.Python.valueToCode(block, 'param2', Blockly.Python.ORDER_ATOMIC);
			  var value_param3 = Blockly.Python.valueToCode(block, 'param3', Blockly.Python.ORDER_ATOMIC);
			  var value_param4 = Blockly.Python.valueToCode(block, 'param4', Blockly.Python.ORDER_ATOMIC);
			  if(value_param1){paramArr.push(value_param1)};
			  if(value_param2){paramArr.push(value_param2)};
			  if(value_param3){paramArr.push(value_param3)};
			  if(value_param4){paramArr.push(value_param4)};
			  var param = paramArr.join(",");
			  var code = "self.ref("+param+")";
			  return [code, Blockly.Python.ORDER_NONE];
			};
		}
}

